{extend name="public/base" /}
{block name="title"}
<h1>编辑角色</h1>
{/block}
{block name="content"}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header">
                </div>
                <form class="form-horizontal" action="{:url('role/edit')}" method="post" id="subForm">
                    {:token()}
                    <input type="hidden" name="id" value="{$role.role_id}">
                    <div class="box-body">
                        {if condition="$role.role_id!=1"}
                        <div class="form-group">
                            <label for="role_name" class="col-sm-3 control-label"><span
                                    class="text-danger">* </span>角色名称</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="role_name" name="role_name"
                                       value="{$role.role_name|default=''}" placeholder="角色名称">
                            </div>
                        </div>
                        {else/}
                        <div class="form-group">
                            <label for="role_name" class="col-sm-3 control-label"><span
                                    class="text-danger">* </span>角色名称</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" disabled
                                       value="{$role.role_name|default=''}" placeholder="角色名称">
                                <input type="text" hidden name="role_name" value="{$role.role_name}">
                            </div>
                        </div>
                        {/if}
                        <div class="form-group">
                            <label for="role_description" class="col-sm-3 control-label">角色描述</label>
                            <div class="col-sm-4">
                                <textarea rows="5" class="form-control" id="role_description" name="role_description" placeholder="角色描述">{$role.role_description|default=''}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 col-md-offset-3 checkbox">
                                {if condition="($role.role_id != 1)"}
                                <label>
                                    <input type="checkbox" name="role_status" value="1" {if $role.role_status==1}checked{/if}>
                                    是否启用
                                </label>
                                {/if}
                                {if condition="($role.role_id == 1)"}
                                <label>
                                    <input type="checkbox" disabled {if $role.role_status==1}checked{/if}>
                                    <input type="hidden" name="role_status" value="{$role.role_status}">
                                    是否启用
                                </label>
                                {/if}
                            </div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <a href="javascript:" class="btn btn-default" onclick="doGoBack()">
                            <i class="fa fa-arrow-left"></i>返回
                        </a>
                        <button type="submit" class="btn btn-primary col-md-offset-3">
                            <i class="fa fa-save"></i>保存
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
{/block}
{block name="script"}
{load href="/static/common/js/validate/jquery.validate.min.js"}
{load href="/static/common/js/validate/messages_zh.min.js"}
{load href="/static/common/js/validate/base.validate.js"}
<script type="text/javascript">
    var doGoBack = function () {
        history.go(-1);
    };
    $(function () {
        var e = "<i class='fa fa-times-circle'></i>";
        $("#subForm").validate({
            rules: {
                role_name: {
                    required: true,
                    maxlength: 20
                },
                role_description: {
                    maxlength: 100
                }
            },
            messages: {
                role_name: {
                    required: e + "请输入角色名称",
                    maxlength: e + "角色名称长度不能超过20个字符"
                },
                role_description: {
                    maxlength: e + "角色描述长度不能超过100个字符"
                }
            }
        })
    });
</script>
{/block}